<?
	
	$ID = $_GET['ID'];
	if (!is_numeric($ID) || $ID <= 0) {
		$smarty->assign("errorOverlay", true);
	    return;
	}
		$smarty->assign("deletedOverlay", true);

	// Delete the PDF file upload and preview images
	@unlink($rootdir.'uploads/'.$ID.'.pdf');
	@unlink($rootdir.'uploads/'.$ID.'_tn_preview.png');
	@unlink($rootdir.'uploads/'.$ID.'_preview.png');
	
	// Remove History
	$sql = "DELETE FROM history WHERE entryID=:entryID";
	$values = array(":entryID"=>$ID);
	$query = $db->prepare($sql);
	$query->execute($values);
		
	// Remove User Metadata
	$sql = "DELETE FROM metadata WHERE entryID=:entryID";
	$values = array(":entryID"=>$ID);
	$query = $db->prepare($sql);
	$query->execute($values);
	
	// Remove Entry
	$sql = "DELETE FROM entries WHERE ID=:ID";
	$values = array(":ID"=>$ID);
	$query = $db->prepare($sql);
	$query->execute($values);
	
	// Refresh after 3 seconds
	header('Refresh: 2; url=index.php');
?>
